// 请款的控制器
angular.module('fundsquest.controller', ['fundsquest.service'])
    .controller("FundsquestCtrl", function ($scope, $rootScope, $http, $ionicModal,$ionicLoading,$timeout) {

//接口

        var CCSessionId = localStorage.getItem("CCSessionId");
        var url = $rootScope.myglobal.serverurl + '/gwb/gwb-phoneset.json?CCSessionId=' + CCSessionId
        $http({
            method: "get",
            url: url,
        })
            .success(function (data) {
                angular.forEach(data, function (item) {
                })
                $scope.fundsquest = data
                $scope.projectlimits = data.projectlimit
                console.log($scope.projectlimits);
            })
            .error(function (data) {

            })







//模版控制

        $ionicModal.fromTemplateUrl('templates/sumrequest.html', {
            scope: $scope
        }).then(function (modal) {
            $scope.modal = modal;
        });

        $scope.openModal = function() {
            $scope.modal.show()
        }
        //$scope.projectlimits 为数据
        //select option改变触发的事件
        $scope.selectChange = function(dateValue){
            console.log(dateValue);
            angular.forEach($scope.projectlimits, function (item) {
                if( item.projectId==dateValue){
                    //总额度
                    $scope.limitAmount=item.limitAmount
                    //已使用金额
                    $scope.backup1=item.backup1


                    //任务id
                        $scope.projectId=item.projectId
                    //虚账户id
                        $scope.vaccountId=item.vaccountId
                    //增加的限额
                        $scope.limitAmount=item.limitAmount
                    //任务名称
                        $scope.projectName=item.projectName
                    //账户组id
                        $scope.accGroupId=item.accGroupId

                    console.log($scope.limitAmount);
                    console.log($scope.backup1);
                }
            })




        };

        //点击提交
        $scope.createContact = function () {

            //选择任务
            var url0 = $rootScope.myglobal.serverurl + '/gwb/gwb-phoneset/1.json?CCSessionId=' + CCSessionId
            $http({
                method: "get",
                url: url0,
                params:{
                    //任务id
                   projectId: $scope.projectId

                    //虚账户id

                    //增加的限额
                    //任务名称
                    //账户组id

                },
            })
                .success(function (data) {
                    console.log(data);
                })
                .error(function (data) {

                })









            $scope.modal.hide();
            $ionicLoading.show({template: "新限额设置成功，请等待审批，原有限额可以正常使用"});
            $timeout(function () {
                $ionicLoading.hide()
            },1000)
            //当前视图被销毁后，同时从内容中移除弹窗，释放内存
            $scope.$on("$destroy", function () {
                $scope.modal.remove()


            })

//             //任务id
//            $scope.projectId
//            //虚账户id
//            $scope.vaccountId
//            //增加的限额
//            $scope.limitAmount
//            //任务名称
//            $scope.projectName
//            //账户组id
//            $scope.accGroupId


        }
        //选择任务
        var url3 = $rootScope.myglobal.serverurl + 'gwb/gwb-phoneset/1/edit.json?CCSessionId=' + CCSessionId
        $http({
            method: "get",
            url: url3,
            params:{
                find_def_flag:1,
                projectEndFlag:0,
                flag:3,
                projects:""
                //任务id
                //虚账户id
                //增加的限额
                //任务名称
                //账户组id

            },
        })
            .success(function (data) {
                console.log(data);
            })
            .error(function (data) {

            })









    })




